package com.bw.aop;

import com.bw.domain.SysUser;
import com.bw.utils.common.JWTUtils;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * @author bobo棒
 * @date 2024年04月08日 16:34
 */

@Aspect
@Component
@Slf4j
public class LogAop2 {
    @Autowired
    HttpServletRequest request;


    @Around("@annotation(com.bw.aop.MyLog)")
    public Object log(ProceedingJoinPoint pjp) throws Throwable {
//访问用户,ip,url,请求参数,访问时间
        //：ip地址、用户名、请求的地址，请求的时间
        String ip=  request.getRemoteAddr();

        String username = JWTUtils.getUserId();

        String uri = request.getRequestURI();

        Date date = new Date();
        log.info("ip地址:{},用户:{},url:{},请求时间:{}",ip,username,uri,date);
        return pjp.proceed();
    }
}
